package com.rwb.springboot.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by ruwenbo on 2018/4/18.
 */
@WebServlet(name = "myServlet", urlPatterns = "/MyServlet", initParams = {@WebInitParam(name = "myname", value = "myValue")})
public class MyServlet extends HttpServlet{

    private String value;

    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        value = servletConfig.getInitParameter("myname");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        PrintWriter writer = resp.getWriter();

        System.out.println("myServlet doGet ...");

        writer.write("hello MyServlet ===> " + value);
    }
}
